package com.testing.thread;

public class TestNoSync {

    public synchronized void m1(){
        System.out.println(Thread.currentThread().getName() +  "m1 start");
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(Thread.currentThread().getName() +  "m1 end");
    }

    public void m2(){
        try {
            Thread.sleep(500);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(Thread.currentThread().getName() +  "m2 end");
    }

    public static void main(String[] args) {
        TestNoSync testNoSync = new TestNoSync();
        // 1.8之后的写法
        new Thread(testNoSync::m1,"m1").start(); // 交错运行，原因是因为M1设置了等待时间
        new Thread(testNoSync::m2,"m2").start();

        // 1.8之前的写法
        new Thread(new Runnable() {
            @Override
            public void run() {
                testNoSync.m1();
            }
        },"m1").start();
    }
}
